package visual;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

import logic.Piece;

public class VisualPiece extends JPanel implements MouseListener, GameDef{

	Piece piece;
	
	public VisualPiece(Piece _piece){
		piece = _piece;
		addMouseListener(this);
	}
	
	public void paint(Graphics g){
		g.setColor(getPieceColor(piece.type));
		for(int i = 0; i < piece.getBlocks().length; i++){
			g.fillRect(piece.getBlocks()[i].getPosition().x, piece.getBlocks()[i].getPosition().y, getParent().getWidth() / GameBoard.WIDTH, getParent().getHeight() / GameBoard.HEIGHT);
		}
	}
	
	public Color getPieceColor(int pieceType){
		switch(pieceType){
			case ID_INTERIOR:
				return new Color(COLOR_INTERIOR);
			case ID_HOUSE:
				return new Color(COLOR_HOUSE);
			case ID_CATAPULT:
				return new Color(COLOR_CATAPULT);
			case ID_CANNON:
				return new Color(COLOR_CANNON);
			case ID_ARMORY:
				return new Color(COLOR_ARMORY);
		}
		return new Color(COLOR_DEFAULT);
	}
	
	public void mouseClicked(MouseEvent e) {
		System.out.println("piece event: " + e);
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
	}

}
